import java.util.Scanner;
import java.util.Arrays;
public class TesrDemo {
    public static void printArray(int[] arr){
        for(int i=0;i<arr.length;i++) {
            System.out.print(arr[i]+" ");
        }
    }

    public static void Init(int[] arr1){
        for(int i=0;i<arr1.length;i++) {
            arr1[i]=i+1;
            System.out.print(arr1[i]+" ");
        }
    }

   /* public static void main(String[] args) {
*//*        int [] arr=new int[]{1,2,3,4,4,5};
        printArray(arr);*//*
   *//*     for(int i=0;i<arr.length;i++) {
            System.out.print(arr[i]+" ");
        }*//*
       *//* int [] arr1=new int[100];
        Init(arr1);*//*
    }*/
  /*  public static void main(String[] args) {        //冒泡
        int[] arr = new int[]{3,6,8,4,6,2,1};
        for(int i=0;i<arr.length-1;i++) {
            for(int j=0;j<arr.length-i-1;j++) {
                if(arr[j]>arr[j+1]) {
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
        }
        printArray(arr);
    }*/

 /*   public static void main(String[] args) {
        *//*int[] arr = new int[]{3,6,8,4,6,2,1};*//*
        int[] arr = new int[]{1,2,3,4,5};
        boolean flag=false;
        for(int j=0;j<arr.length-1;j++) {
            if(arr[j]>arr[j+1]) {
                System.out.print("无序");
                flag=true;
                break;
            }
        }
        if(flag==false) {
            System.out.println("有序");
        }
    }*/

    public static int[] cloneArray(int[] arr1){
        Scanner sc = new Scanner(System.in);
        int[] copy = new int[arr1.length];
        for(int i=0;i<arr1.length;i++) {
            copy[i]=arr1[i];
        }
        return copy;
    }

    /*public static void main(String[] args) {
        int[] arr1 = {1,2,3,4,5};
        int[] copy = cloneArray(arr1);
        printArray(copy);
        String newArr=Arrays.toString(arr1);
        System.out.println(newArr);
    }*/
    public static int binarySearch(int[] array, int target) {
        int left = 0;
        int right = array.length - 1;

        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (array[mid] == target) {
                return mid; // 找到目标值，返回索引
            } else if (array[mid] < target) {
                left = mid + 1; // 在右半部分继续查找
            } else {
                right = mid - 1; // 在左半部分继续查找
            }
        }
        return -1; // 未找到目标值，返回-1
    }

    public static void main(String[] args) {
        int[] array = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19};
        int target = 13;
        int index = binarySearch(array, target);
        if (index != -1) {
            System.out.println("找到目标值，索引为: " + index);
        } else {
            System.out.println("未找到目标值");
        }
    }
}
